package top.krwlc.server.config;

import com.google.gson.Gson;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.json.GsonHttpMessageConverter;
import top.krwlc.server.pojo.User;
import top.krwlc.server.util.DigestUtil;

import java.text.ParseException;
import java.util.UUID;

/**
 * krwlc
 * top.krwlc.server.config
 *
 * @author Lanscarlos
 * @since 2022-04-05 11:42
 */
@SpringBootConfiguration
public class ConfigurationContext {

    /**
     * 测试用例
     * */
    @Bean
    public User user() throws ParseException {
        return new User(
                UUID.randomUUID().toString(),
                "krwlc",
                DigestUtil.digest("666"),
                "可燃乌龙茶",
                "440117197712102333",
                "13700114514"
        );
    }

    @Bean
    public Gson gson() {
        return new Gson();
    }

    /**
     * 处理映射器
     * 自动将 Controller 中返回的对象转换为 JSON 字符串格式
     * */
    @Bean
    public GsonHttpMessageConverter gsonHttpMessageConverter() {
        return new GsonHttpMessageConverter();
    }
}
